<?php
// 本类由系统自动生成，仅供测试用途
class LbsAction extends Action {
	public function getaddress(){
		$address= I('address',0);
		if(!$address){
			$json['status']=0;
			return $this->ajaxReturn($json,"JSON");
		}
	   	$key="96892776e636a0c84da96fe40f2c5511";
	   	$url="http://api.map.baidu.com/geocoder/v2/?address=".urlencode($address)."&output=json&ak=".$key;
	   	$res = json_decode(file_get_contents($url),1);	
	   	if($res['status']!=0){
			$json['status']=0;
			return $this->ajaxReturn($json,"JSON");	   		
	   	}
	   	$back['lng'] = $res['result']['location']['lng'];
	   	$back['lat'] = $res['result']['location']['lat'];

	   	$url="http://api.map.baidu.com/geocoder/v2/?location=".$back['lat'].",".$back['lng']."&output=json&&ak=".$key;;
	   	$res = json_decode(file_get_contents($url),1);
	   	if($res['status']!=0){
			$json['status']=0;
			return $this->ajaxReturn($json,"JSON");	   		
	   	}
	   	$back['province'] = $res['result']['addressComponent']['province'];
	   	$back['city'] = $res['result']['addressComponent']['city'];
	   	$back['district'] = $res['result']['addressComponent']['district'];
	   	$back['status']=1;
	   	return $this->ajaxReturn($back,"JSON");	   	
	}
}